/**
 * <pre>项目名称:LogApp-SpringBoot-Demo 
 * 文件名称:send.java 
 * 包名:com.jk.mq 
 * 创建日期:2017年12月20日下午8:30:30 
 * Copyright (c) 2017, 896670039@qq.com All Rights Reserved.</pre> 
 */
package com.jk.utile;

import java.util.UUID;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

@Component
public class Send  {

    private RabbitTemplate rabbitTemplate;
    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    /**
     * 构造方法注入  
     */
    @Autowired
    public Send(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }


    public void sendMsg(final Object content) {
        taskExecutor.execute(new Runnable() {//匿名内部类 跨类传输参数时 参数设置为final
            public void run() {
                CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("spring-boot-exchange", "spring-boot-routingKey", content, correlationId);
            }
        });

            /*
              convertAndSend(String exchange, String routingKey, final Object object, CorrelationData correlationData)
              exchange:交换机名称                           routingKey:路由关键字       object:发送的消息内容            correlationData:消息ID
             */

    }


}  